import React, { Component } from 'react'
import './index.scss'


export default class Footer
  extends Component {
  handleCheckAll = (event) => {
    this.props.updateAllTodoDone(event.target.checked)
  }
  handleClearAllDone = () => {
    this.props.clearAllDone()
  }

  render() {
    const { todos } = this.props
    const total = todos.length
    const doneCount = todos.reduce((pre, current) => pre + current.done, 0)
    return (
      <div className='todo-footer'>
        <label>
          <input type='checkbox' onChange={this.handleCheckAll} checked={(doneCount > 0 && doneCount === total)} />
        </label>
        <span>已完成{doneCount}</span> /全部{total}
        <button onClick={this.handleClearAllDone} className='btn btn-danger'>清楚已完成任务</button>
      </div>
    )
  }
}
